package cn.iocoder.yudao.module.system.service.autogeneration;

import cn.iocoder.yudao.module.system.controller.admin.examscore.vo.NewExamScoreImportExcelVO;
import cn.iocoder.yudao.module.system.dal.dataobject.examclass.ExamClassDO;
import cn.iocoder.yudao.module.system.dal.dataobject.examclass.ExamClassStudentDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;

import java.util.List;

/**
 * 自动生成 Service 接口
 * 负责根据导入数据自动创建班级、学生、用户账号等
 *
 * @author 芋道源码
 */
public interface AutoGenerationService {

    /**
     * 自动创建班级
     *
     * @param className 班级名称
     * @param grade 年级
     * @param description 描述
     * @return 班级ID
     */
    Long autoCreateClass(String className, String grade, String description);

    /**
     * 自动创建班级（从导入数据中提取信息）
     *
     * @param className 班级名称（如：高二1班）
     * @return 班级ID
     */
    Long autoCreateClassFromName(String className);

    /**
     * 自动创建学生并分配到班级
     *
     * @param studentData 学生数据
     * @param classId 班级ID
     * @return 学生ID
     */
    Long autoCreateStudent(NewExamScoreImportExcelVO studentData, Long classId);

    /**
     * 自动创建学生用户账号
     *
     * @param studentData 学生数据
     * @param classCode 班级编码
     * @return 用户ID
     */
    Long autoCreateStudentUser(NewExamScoreImportExcelVO studentData, String classCode);

    /**
     * 批量自动创建班级和学生
     *
     * @param importDataList 导入数据列表
     * @return 创建结果
     */
    BatchCreationResult batchAutoCreate(List<NewExamScoreImportExcelVO> importDataList);

    /**
     * 解析班级信息
     *
     * @param className 班级名称
     * @return 班级信息
     */
    ClassInfo parseClassInfo(String className);

    /**
     * 生成班级编码
     *
     * @param grade 年级
     * @param classNumber 班级号
     * @return 班级编码
     */
    String generateClassCode(String grade, String classNumber);

    /**
     * 生成学生用户名
     *
     * @param studentName 学生姓名
     * @param classCode 班级编码
     * @param deptId 部门ID（用于区分不同学校/部门）
     * @return 用户名
     */
    String generateStudentUsername(String studentName, String classCode, Long deptId);

    /**
     * 生成学号
     *
     * @param classCode 班级编码
     * @param sequence 序号
     * @return 学号
     */
    String generateStudentNo(String classCode, Integer sequence);

    /**
     * 检查班级是否存在
     *
     * @param className 班级名称
     * @return 班级信息，不存在返回null
     */
    ExamClassDO checkClassExists(String className);

    /**
     * 检查学生是否存在
     *
     * @param studentName 学生姓名
     * @param className 班级名称
     * @return 学生信息，不存在返回null
     */
    ExamClassStudentDO checkStudentExists(String studentName, String className);

    /**
     * 检查用户名是否存在
     *
     * @param username 用户名
     * @return 是否存在
     */
    boolean checkUsernameExists(String username);

    /**
     * 生成唯一用户名
     *
     * @param baseUsername 基础用户名
     * @return 唯一用户名
     */
    String generateUniqueUsername(String baseUsername);

    /**
     * 验证创建数据的有效性
     *
     * @param importDataList 导入数据列表
     * @return 验证结果
     */
    CreationValidationResult validateCreationData(List<NewExamScoreImportExcelVO> importDataList);

    /**
     * 获取默认班主任ID
     *
     * @return 班主任ID
     */
    Long getDefaultTeacherId();

    /**
     * 创建默认班主任账号
     *
     * @param className 班级名称
     * @return 班主任ID
     */
    Long createDefaultTeacher(String className);

    /**
     * 班级信息
     */
    class ClassInfo {
        private String grade;
        private String classNumber;
        private String fullName;
        private String description;
        
        // 构造函数
        public ClassInfo() {}
        
        public ClassInfo(String grade, String classNumber, String fullName, String description) {
            this.grade = grade;
            this.classNumber = classNumber;
            this.fullName = fullName;
            this.description = description;
        }
        
        // Getters and Setters
        public String getGrade() { return grade; }
        public void setGrade(String grade) { this.grade = grade; }
        
        public String getClassNumber() { return classNumber; }
        public void setClassNumber(String classNumber) { this.classNumber = classNumber; }
        
        public String getFullName() { return fullName; }
        public void setFullName(String fullName) { this.fullName = fullName; }
        
        public String getDescription() { return description; }
        public void setDescription(String description) { this.description = description; }
    }

    /**
     * 批量创建结果
     */
    class BatchCreationResult {
        private boolean success;
        private int totalCount;
        private int createdClassCount;
        private int createdStudentCount;
        private int createdUserCount;
        private List<String> createdClasses;
        private List<String> createdStudents;
        private List<String> errorMessages;
        private List<String> warningMessages;
        
        // 构造函数
        public BatchCreationResult() {}
        
        public BatchCreationResult(boolean success, int totalCount, int createdClassCount, 
                                 int createdStudentCount, int createdUserCount,
                                 List<String> createdClasses, List<String> createdStudents,
                                 List<String> errorMessages, List<String> warningMessages) {
            this.success = success;
            this.totalCount = totalCount;
            this.createdClassCount = createdClassCount;
            this.createdStudentCount = createdStudentCount;
            this.createdUserCount = createdUserCount;
            this.createdClasses = createdClasses;
            this.createdStudents = createdStudents;
            this.errorMessages = errorMessages;
            this.warningMessages = warningMessages;
        }
        
        // Getters and Setters
        public boolean isSuccess() { return success; }
        public void setSuccess(boolean success) { this.success = success; }
        
        public int getTotalCount() { return totalCount; }
        public void setTotalCount(int totalCount) { this.totalCount = totalCount; }
        
        public int getCreatedClassCount() { return createdClassCount; }
        public void setCreatedClassCount(int createdClassCount) { this.createdClassCount = createdClassCount; }
        
        public int getCreatedStudentCount() { return createdStudentCount; }
        public void setCreatedStudentCount(int createdStudentCount) { this.createdStudentCount = createdStudentCount; }
        
        public int getCreatedUserCount() { return createdUserCount; }
        public void setCreatedUserCount(int createdUserCount) { this.createdUserCount = createdUserCount; }
        
        public List<String> getCreatedClasses() { return createdClasses; }
        public void setCreatedClasses(List<String> createdClasses) { this.createdClasses = createdClasses; }
        
        public List<String> getCreatedStudents() { return createdStudents; }
        public void setCreatedStudents(List<String> createdStudents) { this.createdStudents = createdStudents; }
        
        public List<String> getErrorMessages() { return errorMessages; }
        public void setErrorMessages(List<String> errorMessages) { this.errorMessages = errorMessages; }
        
        public List<String> getWarningMessages() { return warningMessages; }
        public void setWarningMessages(List<String> warningMessages) { this.warningMessages = warningMessages; }
    }

    /**
     * 创建验证结果
     */
    class CreationValidationResult {
        private boolean valid;
        private List<String> errorMessages;
        private List<String> warningMessages;
        private int duplicateStudentCount;
        private int duplicateClassCount;
        private List<String> invalidClassNames;
        private List<String> invalidStudentNames;
        
        // 构造函数
        public CreationValidationResult() {}
        
        public CreationValidationResult(boolean valid, List<String> errorMessages, 
                                      List<String> warningMessages, int duplicateStudentCount,
                                      int duplicateClassCount, List<String> invalidClassNames,
                                      List<String> invalidStudentNames) {
            this.valid = valid;
            this.errorMessages = errorMessages;
            this.warningMessages = warningMessages;
            this.duplicateStudentCount = duplicateStudentCount;
            this.duplicateClassCount = duplicateClassCount;
            this.invalidClassNames = invalidClassNames;
            this.invalidStudentNames = invalidStudentNames;
        }
        
        // Getters and Setters
        public boolean isValid() { return valid; }
        public void setValid(boolean valid) { this.valid = valid; }
        
        public List<String> getErrorMessages() { return errorMessages; }
        public void setErrorMessages(List<String> errorMessages) { this.errorMessages = errorMessages; }
        
        public List<String> getWarningMessages() { return warningMessages; }
        public void setWarningMessages(List<String> warningMessages) { this.warningMessages = warningMessages; }
        
        public int getDuplicateStudentCount() { return duplicateStudentCount; }
        public void setDuplicateStudentCount(int duplicateStudentCount) { this.duplicateStudentCount = duplicateStudentCount; }
        
        public int getDuplicateClassCount() { return duplicateClassCount; }
        public void setDuplicateClassCount(int duplicateClassCount) { this.duplicateClassCount = duplicateClassCount; }
        
        public List<String> getInvalidClassNames() { return invalidClassNames; }
        public void setInvalidClassNames(List<String> invalidClassNames) { this.invalidClassNames = invalidClassNames; }
        
        public List<String> getInvalidStudentNames() { return invalidStudentNames; }
        public void setInvalidStudentNames(List<String> invalidStudentNames) { this.invalidStudentNames = invalidStudentNames; }
    }

}